package com.project.psc.controller;

import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.psc.bean.BiddBean;
import com.project.psc.dto.SupplierDto;
import com.project.psc.service.IBiddService;
import com.project.psc.util.SupplierThreadLocal;
import com.project.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;


@RestController
@RequestMapping("bidd")
public class BiddController {
    @Autowired
    private IBiddService biddService;
    @GetMapping("add")
    public ResultVo add(BiddBean biddBean){
        SupplierDto loginUser = SupplierThreadLocal.getSupplier();
        biddBean.setSupplierName(loginUser.getSupplierName());
        biddService.add(biddBean, loginUser.getId());
        return ResultVo.ok();
    }

    @GetMapping("cutByItem")
    public ResultVo cutByItem(Integer pageNO, String title, LocalDate startDate, LocalDate endDate){
        SupplierDto loginUser = SupplierThreadLocal.getSupplier();
        IPage<BiddBean> biddBeanIPage = biddService.cutByItem(pageNO, loginUser.getId(), title, startDate, endDate);
        return ResultVo.ok(biddBeanIPage);
    }
    @GetMapping("findById")
    public ResultVo findById(Long id){
        BiddBean byId = biddService.findById(id);
        return ResultVo.ok(byId);
    }

}
